package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.${entityName}Mapper;
import com.bw1806.pojo.${entityName};
import com.bw1806.pojo.${entityName}Example;
import com.bw1806.sellergoods.service.${entityName}Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class ${entityName}ServiceImpl implements ${entityName}Service {

    @Autowired
    private ${entityName}Mapper ${entityNameLower}Mapper;

    @Override
    public List<${entityName}> findAll() {
        return ${entityNameLower}Mapper.selectByExample(null);
    }

    @Override
    public PageResult<${entityName}> pagelist(${entityName} ${entityNameLower},int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        ${entityName}Example example=new ${entityName}Example();

        ${entityName}Example.Criteria criteria = example.createCriteria();

        if(${entityNameLower}!=null){
            //if(${entityNameLower}.getName()!=null && ${entityNameLower}.getName().length()>0){
            //    criteria.andNameLike("%"+${entityNameLower}.getName()+"%");
           // }
        }

        Page<${entityName}> page= (Page<${entityName}>) ${entityNameLower}Mapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(${entityName} ${entityNameLower}) {
        Long id = ${entityNameLower}.getId();
        if(id != null && id !=0){
            ${entityNameLower}Mapper.updateByPrimaryKey(${entityNameLower});
        } else{
            ${entityNameLower}Mapper.insert(${entityNameLower});
        }
    }

    @Override
    public ${entityName} getById(Long id) {
        return ${entityNameLower}Mapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            ${entityNameLower}Mapper.deleteByPrimaryKey(id);
        }
        //${entityNameLower}Mapper.deletebth(ids);
    }
}
